package cheme.ProcessEditor.Figures.Util;

import org.eclipse.draw2d.Figure;
import org.eclipse.gef.commands.Command;

import cheme.ProcessModel.Cmds.ChemeCommand;

public class MoveTagCmd extends ChemeCommand
{
	TagLocator locator = null;
	int newX = 0;
	int oldX = 0;
	int newY = 0;
	int oldY = 0;
	Figure figure;
	
	public MoveTagCmd(Figure figure, TagLocator locator, int newX, int newY)
	{
		super(null);
		
		super.setLabel("Move Tag comand!");
		
		this.figure = figure;
		this.locator = locator;
		this.newX = newX;
		this.newY = newY;
	}

	@Override
	public boolean canExecute()
	{
		return super.canExecute();
	}

	@Override
	public void primExecute()
	{
		oldX = locator.getXGap();
		oldY = locator.getYGap();
		
//		System.out.println("Moving from (" + oldX + "," + oldY + ") to (" + newX + "," +  newY + ")");
		
		locator.setXGap(newX);
		locator.setYGap(newY);
		locator.relocate(figure);
		figure.getParent().revalidate();
	}

	@Override
	public void primRedo()
	{
		locator.setXGap(newX);
		locator.setYGap(newY);
		locator.relocate(figure);
		figure.getParent().revalidate();
	}

	@Override
	public void primUndo()
	{
		locator.setXGap(oldX);
		locator.setYGap(oldY);
		locator.relocate(figure);
		figure.getParent().revalidate();
	}
}
